import { NgModule, ModuleWithProviders, Optional, SkipSelf, OpaqueToken } from '@angular/core';
import { Http, HttpModule, JsonpModule } from '@angular/http';

import { PlayerService } from '../http/http-player.service';
import { AuthService } from './auth.service';
import { DialogService } from './dialog.service';

import { AuthGuard } from './auth-guard.service';
import { CanDeactivateGuard } from '../can-deactivate-guard.service';

export const URL_CONFIG = new OpaqueToken('urlConfig');

const urls: any[] = [
    // { provide: HeroService, useFactory: heroServiceFactory, deps: [Logger, UserService] },
    {
        provide: URL_CONFIG, useValue: {
            playersUrl: 'http://121.40.82.99:8003/apis/soccer/players',
            playerUrl: 'http://121.40.82.99:8003/apis/soccer/players/',
            updatePlayerUrl: 'http://121.40.82.99:8003/apis/soccer/players/update'
        }
    }

];
@NgModule({
    providers: [],
    exports: [HttpModule, JsonpModule]
})
export class ShareServiceModule {
    static forRoot(): ModuleWithProviders {
        return {
            ngModule: ShareServiceModule,
            providers: [
                AuthService, DialogService, AuthGuard, CanDeactivateGuard, urls,
                { provide: PlayerService, useClass: PlayerService, deps: [Http, URL_CONFIG] }
            ]
        };
    }
    constructor( @Optional() @SkipSelf() parentModule: ShareServiceModule) {
        if (parentModule) {
            throw new Error(
                'CoreModule is already loaded. Import it in the AppModule only');
        }
    }
}
